package com.cherrish.demo.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author cherrish
 * @time 2018-08-30 15:01
 * @name MessageSender
 * @desc:
 */
@EnableScheduling
@Component
public class MessageSender {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Scheduled(fixedRate = 2000)
    public void sendMessage(){
        stringRedisTemplate.convertAndSend("send", String.valueOf(Math.random()));
    }

    @Scheduled(fixedRate = 2000)
    public void replyMessage(){
        stringRedisTemplate.convertAndSend("reply", String.valueOf(Math.random()));
    }
}
